layui.use(['layer','form','table','element'],function () {
    var layer = layui.layer
        ,form = layui.form
        ,table =layui.table
        ,element = layui.element;

    //初始化数据表格
     table.render({
         elem:"#data"
         ,height: 'full-150'
         ,url:"/admin/submitArtAdmin/getProjectList"
         ,cellMinWidth: 80
         ,cols: [[
             {field:'id',width:60,title: 'ID', sort: true}
             ,{field:'title', title: '标题'}
             ,{field:'', width:90,title: '状态', toolbar: '#statusBar'}
             ,{field:'memo',width:110,title: '备注',sort: true}
             ,{templet:'<div>{{d.author}}</div>',width:110,title: '作者',sort: true}
             ,{field:'showCreateTime',width:220,title: '创建时间',sort: true}
             ,{field:'',width:380,title: '操作',toolbar: '#barDemo'}
         ]]
         ,page:true
     });

     //监听工具条
     table.on('tool(dataTable)',function (obj) {
         var data = obj.data;
         if(obj.event == 'detail'){
             var url = "/admin/submitArt/descAndEdit/"+data.id;
             $(this).attr("data-url",url);
             parent.addTab($(this));

         }else if(obj.event == 'del'){
            //删除项目
             layer.confirm('确定删除？', function(index){
                 layer.msg('登录中...', { icon: 16, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: '50%', time: 300000 });

                 $.ajax({
                    type:"POST"
                     ,url:"/admin/submitArt/delete"
                     ,data:{
                        id:data.id
                     }
                     ,success:function (result) {
                         layer.msg(result.message);
                         table.reload("data");
                     }
                     ,error:function () {
                         layer.msg("系统错误");
                     }

                 });

             });
         }else if(obj.event == 'pass'){

             layer.confirm('确认通过？', function(index){
                 layer.msg('操作中...', { icon: 16, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: '50%', time: 300000 });

                 $.ajax({
                     type:"POST"
                     ,url:"/admin/submitArtAdmin/pass"
                     ,data:{
                         id:data.id
                     }
                     ,success:function (result) {
                         layer.msg(result.message);
                         table.reload("data");
                     }
                     ,error:function () {
                         layer.msg("系统错误");
                     }

                 });

             });

         }else if(obj.event == 'fail'){

             layer.confirm('<input type="text" placeholder="请输入审核失败原因" id="memo" name="memo" class="layui-input">', function(index){
                 layer.msg('操作中...', { icon: 16, shade: [0.5, '#f5f5f5'], scrollbar: false, offset: '50%', time: 300000 });

                 $.ajax({
                     type:"POST"
                     ,url:"/admin/submitArtAdmin/fail"
                     ,data:{
                         id:data.id,
                         memo:$("#memo").val()
                     }
                     ,success:function (result) {
                         layer.msg(result.message);
                         table.reload("data");
                     }
                     ,error:function () {
                         layer.msg("系统错误");
                     }

                 });

             });

         }else if(obj.event == 'qrcodeDetail'){
             var pay = data.pay;
             layer.open({
                 type: 1
                 ,id: 'layerDemo' //防止重复弹出
                 ,content: '<img src="'+pay+'" width="300px">'
                 ,btn: '关闭全部'
                 ,btnAlign: 'c' //按钮居中
                 ,shade: 0 //不显示遮罩
                 ,yes: function(){
                     layer.closeAll();
                 }
             });
         }else {
             //编辑项目
            layer.msg("操作错误！");
         }
     });

    function rightMenu(){

        $(".layui-tab-title li",window.parent.document).on("contextmenu",function (e) {
            var rightmenu = $(".rightmenu",window.parent.document);
            rightmenu.find("li").attr('data-id',$(this).attr("lay-id"));
            l = e.clientX;
            t = e.clientY;
            rightmenu.css({ left:l, top:t}).show();
            return false;
        });
        //左键点击隐藏
        $("body,.layui-tab-title li",window.parent.document).click(function(){
            $(".rightmenu").hide();
        });

    }

    function iframeWH(){
        var H = $(window).height();
        $("iframe",window.parent.document).css("height",H+"px");
    }
     
     //搜索
    $("#search").on("click",function () {
        table.reload("data",{
            page:{
                curr:1
            }
            ,where:{
                title:$("#title").val(),
                author:$("#author").val(),
                typeId:$("#type").val(),
                labelId:$("#label").val(),
                commented:$("#commented").val()
            }
        })
    });;


    $("#updateSiteMap").on("click",function () {

        $.ajax({
            type:"POST"
            ,url:"/admin/system/updateSiteMap"
            ,success:function (result) {
                layer.msg(result.message);
            }
            ,error:function () {
                layer.msg("系统错误");
            }

        });


    });

});
